package com.abc.scholarship.exception;

import com.abc.scholarship.domain.vo.resp.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-07-03  16:41
 */
@Slf4j
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = BusinessException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ApiResult<?> businessException(BusinessException e){
        log.info("business exception!the reason is {}", e.getMessage(), e);
        return ApiResult.fail(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ApiResult<?> exceptionError(Exception e){
        log.info("system exception!the reason is {}", e.getMessage(), e);
        return ApiResult.fail("系统内部异常");
    }


}
